from time import sleep

from selenium.webdriver.common.by import By
from common.base import Base
from common.functions import open_browser


class AssociatedArticle(Base):
    # 点击商品管理标签
    def click_goods_management(self):
        self.base_click((By.XPATH, '//div[@id="menu-list"]/ul/li[2]'))

    # 点击添加新商品标签
    def click_add_new_goods(self):
        self.base_click((By.LINK_TEXT, '添加新商品'))

    # 点击关联文章
    def click_article(self):
        self.base_switch_default_iframe()
        self.base_switch_iframe((By.ID, 'main-frame'))
        self.base_click((By.ID, 'article-tab'))

    # 选择文章标题
    # 搜索栏输入
    def input_find(self, content):
        self.base_send_keys((By.NAME, 'article_title'), content)

    # 点击搜索
    def find(self):
        self.base_click((By.CSS_SELECTOR, '#article-table input[value=" 搜索 "]'))

    # 可选文章
    def optional_goods(self, content):
        self.base_select_value((By.NAME, 'source_select3'), content)

    # 全部右移
    def all_to_right(self):
        self.base_click((By.CSS_SELECTOR, '#article-table input[value=">>"]'))

    # 单个右移
    def one_to_right(self):
        self.base_click((By.CSS_SELECTOR, '#article-table input[value=">"]'))

    # 单个左移
    def one_to_left(self):
        self.base_click((By.CSS_SELECTOR, '#article-table input[value="<"]'))

    # 全部左移
    def all_to_left(self):
        self.base_click((By.CSS_SELECTOR, '#article-table input[value="<<"]'))

    # 跟商品关联的商品
    def goods_optional_goods(self, content):
        self.base_select_value((By.NAME, 'target_select3'), content)

    # 点击重置按钮
    def reset(self):
        self.base_switch_default_iframe()
        self.base_switch_iframe((By.ID, "main-frame"))
        self.base_click((By.XPATH, "//div[@class='button-div']/input[3]"))

    # 点击确定按钮
    def sure(self):
        self.base_switch_default_iframe()
        self.base_switch_iframe((By.ID, "main-frame"))
        self.base_click((By.XPATH, "//div[@class='button-div']/input[2]"))

